# -*- coding: utf-8 -*-
"""
Created on Tue May  9 16:23:40 2023

@author: lenovo
"""

from osgeo import gdal
import glob


path=r'H:\company\公司项目\陕西\商洛\data\test'
path2=r'H:\company\公司项目\陕西\商洛\data'


# 设置输入文件路径
input_files = glob.glob(path+'\\'+'*.tif')
# 设置输出文件路径
output_file = path2+'\\merged\\'+'test.tif'

inputrasfile=[]
for fn in input_files:
    infn=gdal.Open(fn, gdal.GA_ReadOnly)
    inputProj1 = infn.GetProjection()
    inputrasfile.append(infn)
    

options=gdal.WarpOptions(srcSRS=inputProj1, dstSRS=inputProj1,format='GTiff')
gdal.Warp(output_file,inputrasfile,options=options)


